package com.lam.common.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

import com.lam.common.utils.SpringUtils;
import com.lam.common.utils.StringUtils;

@Configuration
public class CommonConfig {
	
	@Value("${spring.profiles.active}")
	private String env;
	
	@Value("${server.port}")
	private String port;
	
	/** 根路径 */
	@Value("${server.servlet.context-path}")
	private String contextPath;
	
	/** 后端接口url前缀 */
	@Value("${adminPath}")
	private String adminPath;
	
	/** 前端app端接口url前缀 */
	@Value("${frontPath}")
	private String frontPath;
	
	public static CommonConfig me() {
		return SpringUtils.getBean(CommonConfig.class);
	}
	
	public String getContextPath() {
		return StringUtils.isBlank(contextPath)||contextPath.equals("/")?"":(contextPath.startsWith("/")?contextPath:"/"+contextPath);
	}

	public String getAdminPath() {
		return String.format("/%s/", adminPath);
	}

	public String getFrontPath() {
		return String.format("/%s/", frontPath);
	}

	public String getEnv() {
		return env;
	}
	
	public boolean isDev() {
		return StringUtils.equalsIgnoreCase(env, "dev");
	}
	public boolean isSit() {
		return StringUtils.equalsIgnoreCase(env, "sit");
	}
	public boolean isPrd() {
		return StringUtils.equalsIgnoreCase(env, "prd");
	}

	public String getPort() {
		return port;
	}

}
